import React from "react";
import context from "../ThemeContext";

class VoteMain extends React.Component {
  static contextType = context;
  render() {
    const { store } = this.context;
    const { oppNum, supNum } = store.getState();
    return (
      <div>
        <p>支持人数：{supNum}人</p>
        <p>反对人数：{oppNum}人</p>
      </div>
    );
  }

  componentDidMount() {
    const { store } = this.context;
    // 目的：组件第一次渲染完毕，把“让组件更新的方法”，基于store.subscribe放入到事件池中！！
    // 类组键可以直接使用foreUpdate让组件重新更新
    store.subscribe(() => {
      this.forceUpdate();
    });
  }
}

export default VoteMain;
